import { Context } from 'koa';
import { success } from '../utils/response';
import { testMySQLConnection } from '../database/mysql';
import { testRedisConnection } from '../database/redis';

/**
 * 服务健康检查
 */
export async function healthCheck(ctx: Context): Promise<void> {
  const checks = {
    koa: true,
    mysql: false,
    redis: false,
  };

  // 检查MySQL
  checks.mysql = await testMySQLConnection();

  // 检查Redis
  checks.redis = await testRedisConnection();

  const allHealthy = Object.values(checks).every(v => v === true);

  success(ctx, {
    status: allHealthy ? 'healthy' : 'unhealthy',
    checks,
    timestamp: new Date().toISOString(),
  });
}

